export module DEF {

  //-------------------------------------------------------------------------------
  //                              SEVER
  //-------------------------------------------------------------------------------
  export namespace SEVER {

    export const enum TYPE {
      GATE = 'gate',
      CONNECTOR = 'connector',
      DATABASE = 'database',
      LOBBY = 'lobby',
      ROOM = 'room',
      DOUDIZHU = 'doudizhu'
    }

    export const enum ID {
      GATE = 'gate',
      CONNECTOR_1 = 'connector-1',
      CONNECTOR_2 = 'connector-2',
      DATABASE = 'database-1',
      LOBBY = 'lobby-1',
      ROOM = 'room-1',
      DOUDIZHU = 'doudizhu-1'
    }
  }

  //-------------------------------------------------------------------------------
  //                              SYSTEM
  //-------------------------------------------------------------------------------
  export namespace SYSTEM {

    export const enum TOKEN {
      SECRET_OR_PRIVATE_KEY = 'system',
      EXPIRES_IN = '1h'
    }

    export const enum RETURN_CODE {
      SUCCESS = 200,
      ERROR = 0
    }

    export const enum LOGIN_CODE {
      SUCCESS = 200,
      FAIL_NOT_EXIST = 500,    // User does not exist
      FAIL_WRONG = 501,        // Wrong account or password
      FAIL_DUPLICATE = 502,    // Duplicate login
    }

    export const enum MATCH_CODE {
      SUCCESS = 200,
      FAIL_GAME_NOT_EXIST = 500,    // 游戏模式不存在
      FAIL_USER_ERROR = 501,        // 用户不存在/离线
      FAIL_IS_MATCHING = 502,       // 已经在匹配中
      FAIL_ALREADY_IN_ROOM = 503,   // 已经在房间中
    }
  }

  //-------------------------------------------------------------------------------
  //                              User
  //-------------------------------------------------------------------------------
  export namespace USER {

    export const ID_INVALID: number = 0;

    export const enum TYPE {
      ADMIN = 'sa',           // 管理员
      TEACHER = 'teacher',    // 老师
      STUDENT = 'student',    // 学生
      UNDEFINED = 'undefined' // 未定义
    }
  }

  //-------------------------------------------------------------------------------
  //                              Player
  //-------------------------------------------------------------------------------
  export namespace PLAYER {

    export const enum STATE {
      UNKNOW = 0,     // 未知
      SITDOWN = 1,    // 坐下
      READY = 2,      // 准备中
      LOADING = 3,    // 场景资源加载中
      LOADED = 4,     // 场景资源已加载
      PLAYING = 5,    // 游戏中
      OFFLINE = 6,    // 离线
      SEEING = 7      // 观战
    }

    export const enum ACTION {
      SITDOWN = 0,    // 坐下
      READY = 1,      // 准备
      START = 2,      // 开始
      SEEING = 3      // 旁观
    }

    export const enum LEAVE {
      NORMAL = 0,         // 正常离开
      KICK = 1,           // 被t
      ESCAPE = 2,         // 逃跑
      NOT_IN_ROOM = 3,    // 不在房间中
      CANT_LEAVE = 4,     // 不能离开
      DISSOLVE = 5        // 解散
    }

    export const enum UPDATE {
      ADD = 0,            // 新增
      UPDATE_NAME = 1,    // 改名
      UPDATE_STATE = 2,   // 状态
      UPDATE_OFFINE = 3   // 离线
    }
  }

  //-------------------------------------------------------------------------------
  //                              Game
  //-------------------------------------------------------------------------------
  export namespace GAME {

    export const enum MODE {
      unknow = 0,     // 未知
      doudizhu = 1,   // 斗地主
      lushi = 2,      // 炉石
    }

    export const enum STATE {
      INVALID = 0,
      WAITING = 1,    // 等待开始
      LOADING = 2,    // 玩家开始加载场景资源
      PLAYING = 3,    // 游戏正式进行中
      END = 4         // 游戏结束
    }
  }

  //-------------------------------------------------------------------------------
  //                              Room
  //-------------------------------------------------------------------------------
  export namespace ROOM {

    export const ID_INVALID: number = 0;
    export const ID_BEGIN: number = 100000;
    export const ID_END: number = 999999;

    export const MAX_WAIT_TIME: number = 20;    // 单位分钟, 最多等待20分钟
    export const MAX_EXIST_TIME: number = 1440; // 最长存在一天

    export const enum STATE {
      NONE = 0,
      CREATE = 1,
      REMOVE = 2,
      UPDATE = 3
    }

    export const enum JOIN_RESULR {
      SUCCESS = 0,
      FAIL_ROOM_NOT_EXIST = 1,    // 房间不存在
      FAIL_NO_FREE_ROOM = 2,      // 不能加入
      FAIL_ACCOUNT_ERR = 3,       // 用户不存在
      FAIL_ALREADY_IN_ROOM = 4,   // 已经在房中
      FAIL_GAME_IS_START = 5,     // 游戏已开始
      FAIL_SYSERR = 6             // 系统错误
    }

    export const enum LEAVE_TYPE {
      NORMAL = 0,             // 正常退出
      WAIT_TIMEOUT = 1,       // 等待游戏开始时间过长
      EXIST_TIMEOUT = 2,      // 超出最长房间占用时间
      OWNER_OFFLINE = 3,      // 房主掉线
      OWNER_DISSOLVE = 4,     // 房主解散房间
      GAMEEND = 5             // 游戏结束
    }
  }
}
